var goodlist = {
    getCount: function(con, orderType, order) {
        var p = new Promise(function(resolve, reject) {
            $.ajax({
                type: "get",
                url: "../php/count.php",
                data: {
                    con,
                    orderType,
                    order
                },
                dataType: "json",
                success: function(data) {
                    resolve(data)
                }

            })
        })
        return p
    },
    getData: function(con, orderType, order,showNum, pageindex) {
        var p = new Promise(function(resolve, reject) {
            $.ajax({
                type: "get",
                url: "../php/getData.php",
                data: {
                    con,
                    orderType,
                    order,
                    showNum,
                    pageindex
                },
                dataType: "json",
                success: function(data) {
                    resolve(data)
                }

            })
        })
        return p
    }
}

    var con = ""
    var orderType = "goods_id" 
    var order = "asc"
    var showPage = 3
    var showNum=9

    $(".box_left ul li div").on("click",function(){
        $(this).css({
            background:"#ffcb00",
            border: "1px solid #ffcb00"
        })
        $a=$(this).parent().siblings().children("div").css({
            background:"#ffffff",
            border: "1px solid #001022"
        })
        con=$(this).parent().text()
        update()
    })

    $(".img1").on("click",function(){
        orderType="goods_price_num"
        order="asc"
        update()
    })
    $(".img2").on("click",function(){
        orderType="goods_price_num"
        order="desc"
        update()
    })
    $(".img3").on("click",function(){
        orderType="goods_id" 
        order="asc"
        update()
    })
    $(".img4").on("click",function(){
        orderType="goods_id" 
        order="desc"
        update()
    })
    update()
   function update(){
    goodlist.getCount(con, orderType, order).then(function(count){
        new Page(".page", {
            count: count,
            showNum: showNum,
            showPage: showPage,
            callback: function(pageindex) {
                goodlist.getData(con, orderType, order,showNum, pageindex).then(function(e){
                     console.log(e)
                     var html=""
                     e.forEach(item => {
                         html +=`<li>
                         <a href="../html/goodsdetail.html?goods_id=${item.goods_id}&goods_menu=${item.goods_menu}">
                         <img src="${item.goods_img}" alt="">
                         <p>${item.goods_title}</p>
                         <p>${item.goods_price}</p>
                         <div>立即购买</div>
                         </a>
                           </li>`
                     });
                     console.log(html)
                     $(".goods").html(html)
                })
            }
            })
    })
   }
    


    
    

    

